package com.system.service.impl;

import com.system.mapper.DirectMapper;
import com.system.po.info.Personnel;
import com.system.service.DirectService;
import lombok.val;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DirectServiceimpl implements DirectService {

    @Autowired
    private DirectMapper directMapper;


    @Override
    public Boolean addCommandere(Personnel personnel) {      //增加总指挥
        Personnel personnel1 = this.publicaddCommandere(personnel,"总指挥");
        Boolean  addCommandere=directMapper.addCommandere(personnel1);
        return addCommandere;

    }

    @Override
    public Boolean addViceCommandere(Personnel personnel) {           //增加副总指挥
        Personnel personnel1 = this.publicaddCommandere(personnel,"副总指挥");
        Boolean  addCommandere=directMapper.addCommandere(personnel1);
        return addCommandere;
    }


    @Override
    public Boolean addDeputySafetyDirecto(Personnel personnel) {       //增加安全副矿长
        Personnel personnel1 = this.publicaddCommandere(personnel,"安全副矿长");
        Boolean  addCommandere=directMapper.addCommandere(personnel1);
        return addCommandere;
    }





    @Override
    public Boolean addRescueBrigade(Personnel personnel) {             //增加救援大队
        Personnel personnel1 = this.publicaddCommandere(personnel,"救援大队");
        Boolean  addCommandere=directMapper.addCommandere(personnel1);
        return addCommandere;
    }

    @Override
    public List<Personnel> queryCommandere() {
        return directMapper.queryCommandere("总指挥");
    }

    @Override
    public List<Personnel> queryViceCommandere() {
        return directMapper.queryCommandere("副总指挥");
    }

    @Override
    public List<Personnel> queryDeputySafetyDirecto() {
        List<Personnel> queryCommandere = directMapper.queryCommandere("安全副矿长");
        return queryCommandere;
    }

    @Override
    public Personnel Singlearticle(Integer id) {
        return  directMapper.Singlearticle(id);
    }

    @Override
    public List<Personnel> queryRescueBrigade() {
        return directMapper.queryCommandere("救援大队");
    }


    @Override
    public Boolean editwholeCommandere(Personnel personnel) {         //修改救援大队
        Personnel personnel1 = this.publiceditCommandere(personnel);
        Boolean  editCommanderel=directMapper.editCommanderel(personnel1);
        return editCommanderel;
    }


    @Override
    public Boolean deletewholeCommandere(Personnel personnel) {         //删除角色
        Boolean deletewholeCommandere = directMapper.deletewholeCommandere(personnel.getId());
        return deletewholeCommandere;
    }


    private  Personnel publicaddCommandere(Personnel personnel,String name){      //增加方法体总指挥
        Personnel personnel1=new Personnel();
        personnel1.setName(name);
        personnel1.setPosition(personnel.getPosition());
        personnel1.setUser_name(personnel.getUser_name());
        personnel1.setOfficephone(personnel.getOfficephone());
        personnel1.setPhonenum(personnel.getPhonenum());
        personnel1.setTelephone(personnel.getTelephone());
        personnel1.setOtherphone(personnel.getOtherphone());
        return personnel1;
    }

    private  Personnel publiceditCommandere(Personnel personnel){      //增加方法体总指挥
        Personnel personnel1=new Personnel();
        personnel1.setId(personnel.getId());
        personnel1.setPosition(personnel.getPosition());
        personnel1.setUser_name(personnel.getUser_name());
        personnel1.setOfficephone(personnel.getOfficephone());
        personnel1.setPhonenum(personnel.getPhonenum());
        personnel1.setTelephone(personnel.getTelephone());
        personnel1.setOtherphone(personnel.getOtherphone());
        return personnel1;
    }
}
